package com.mars.push.core.channel;


import com.mars.push.api.common.MessageInput;

/**
 * @Author King
 * @create 2020/7/10 11:35
 */
public abstract class AbstractPushChannel implements PushChannel {

    @Override
    public Object iosPush(MessageInput messageInput) {
        return iosPush0(createMessage(messageInput));
    }

    @Override
    public Object androidPush(MessageInput messageInput) {
        return androidPush0(createMessage(messageInput));
    }

    @Override
    public Object allPush(MessageInput messageInput) {
        return allPush0(createMessage(messageInput));
    }

    /**
     * IOSPush 模板方法 子类实现
     *
     * @param pushMessage
     * @return
     */
    protected abstract Object iosPush0(PushMessage pushMessage);


    /**
     * androidPush0 模板方法 子类实现
     *
     * @param pushMessage
     * @return
     */
    protected abstract Object androidPush0(PushMessage pushMessage);


    /**
     * allPush0 模板方法 子类实现
     *
     * @param pushMessage
     * @return
     */
    protected abstract Object allPush0(PushMessage pushMessage);


    /**
     * 模板方法 子类实现
     *
     * @param input
     * @return
     */
    public abstract PushMessage createMessage(MessageInput input);


    /**
     * 执行成功的时候执行
     *
     * @param message
     * @param result
     */
    protected abstract void onSuccess(PushMessage message, Object result);

    /**
     * 执行失败的时候执行
     *
     * @param message
     * @param result
     */
    protected abstract void onFail(PushMessage message, Object result);


    /**
     * 执行异常的时候执行
     *
     * @param message
     * @param result
     */
    protected abstract void onException(PushMessage message, Object result);
}
